package com.jiepuxun.demo.common;

import java.util.HashMap;
import java.util.Map;

public class Ret {

    private Integer code;
    private Boolean success;
    private String message;
    private Map<String,Object> data;

    public Integer getCode() {
        return code;
    }

    public Ret setCode(Integer code) {
        this.code = code;
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public Ret setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Ret setMessage(String message) {
        this.message = message;
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public Ret setData(String key,Object data){
        if (this.data == null){
            this.data = new HashMap<>();
        }
        this.data.put(key,data);
        return this;
    }

    public Ret setData(Map<String, Object> data) {
        this.data = data;
        return this;
    }

    public static Ret ok(){
        return new Ret().setSuccess(true).setMessage("success").setCode(200);
    }

    public static Ret error(){
        return new Ret().setSuccess(false).setMessage("fail").setCode(500);
    }
}
